VERSION 5.00
Begin VB.Form fTest 
   AutoRedraw      =   -1  'True
   Caption         =   "Async FolderCopy (per RC5-threading)"
   ClientHeight    =   4680
   ClientLeft      =   60
   ClientTop       =   435
   ClientWidth     =   8685
   LinkTopic       =   "Form1"
   ScaleHeight     =   4680
   ScaleWidth      =   8685
   StartUpPosition =   3  'Windows-Standard
   Begin VB.CommandButton cmdStart 
      Caption         =   "Start threaded copy"
      Height          =   375
      Left            =   180
      TabIndex        =   1
      Top             =   180
      Width           =   1755
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "Cancel threaded copy"
      Enabled         =   0   'False
      Height          =   375
      Left            =   2040
      TabIndex        =   0
      Top             =   180
      Width           =   1995
   End
End
Attribute VB_Name = "fTest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
 
Private WithEvents TH As cThreadHandler
Attribute TH.VB_VarHelpID = -1

Private Sub Form_Load() 'first let's instantiate the ThreadClass (regfree) on its own thread, returning "a Handler"
  Set TH = New_c.RegFree.ThreadObjectCreate("FolderCopyThread" & App.ThreadID & ObjPtr(Me), App.Path & "\ThreadLib.dll", "cCopyThread")
End Sub
 
Private Sub cmdStart_Click()
  Cls
  cmdStart.Enabled = False: cmdCancel.Enabled = True
  CopyFolderAsync "E:\Backup\DataMatrix", "C:\Code\DataMatrix", True
End Sub

Private Sub cmdCancel_Click()
  cmdStart.Enabled = True: cmdCancel.Enabled = False
  If TH.JobQueueCount Then TH.CancelExecution
End Sub

Private Function CopyFolderAsync(ByVal DstFolder As String, ByVal SrcFolder As String, Optional ByVal ApplyFileAttributesToDst As Boolean, Optional ByVal FilterSemicolonSeparated As String) As String
  TH.CallAsync "CopyFolderTo", DstFolder, SrcFolder, ApplyFileAttributesToDst, FilterSemicolonSeparated
End Function

'Our TH-Object is the clientside ThreadHandler, who's able to communicate with the Thread
'raising appropriate Events here, when results come back (in case of the async-calls)
Private Sub TH_ThreadEvent(MethodName As String, EventName As String, ByVal ParamCount As Long, P1 As Variant, P2 As Variant, P3 As Variant, P4 As Variant, P5 As Variant, P6 As Variant, P7 As Variant, P8 As Variant)
Dim PercentFactor As Double, ProgrFileSizeInSrc As Currency, TotalFileSizeInSrc As Currency
    PercentFactor = P1
    ProgrFileSizeInSrc = P2
    TotalFileSizeInSrc = P3
  Caption = "Copy-Operation in progress: " & Format$(PercentFactor, "Percent")
End Sub

Private Sub TH_MethodFinished(MethodName As String, Result As Variant, ErrString As String, ErrSource As String, ByVal ErrNumber As Long)
  Print vbLf; vbLf; vbLf; vbLf; "MethodFinished-Event of TH for: "; MethodName; " with Err-ResultString: "; vbLf; Result
  cmdStart.Enabled = True: cmdCancel.Enabled = False
End Sub
